
var can,ctx;
var w,h;

var girlImg =  new Image();
var  starImg = new Image();

var lastTime  ;
var deltaTime ;

var percent = 0;
window.onload = function(){
	can = document.getElementById("canvas");
	ctx = can.getContext("2d");
	w = can.width;
	h = can.height;

	
    starImg.src = "src/star.png";
    girlImg.src = "src/back.jpg";

	for(var i = 0;i<num;i++){
	   var star = new StarObj();
	   star.init();
	   stars.push(star);
    }
  
    lastTime = Date.now();

    can.addEventListener("mousemove",changeAlpha);   //onmouseout  onclick  等等带有前前缀的用于can.onclick = function(){}
	can.addEventListener("mouseout",changeAlpha1); 
	startloop();                               //jquery 以及addEventListener 不带前缀on

}

function drawBackground(){
	ctx.fillStyle = "#393500";
	ctx.fillRect(0,0,w,h);
	ctx.drawImage(girlImg,50,50,700,500);
}

function startloop(){
	  window.requestAnimFrame(startloop);
	  drawBackground();
	  drawStars();
      var now = Date.now();
      deltaTime  = now - lastTime;
      lastTime = now;
     // console.log(deltaTime);
}

function changeAlpha(){
	percent += 0.001*deltaTime;
	if(percent>1){
		percent = 1;
	}
}
function changeAlpha1(){
		percent = 0;	
}